import { Form, FormInstance, Input, Select } from 'antd';
import React, { useEffect } from 'react';

interface MaterialPropertyFormProps<FormProps> {
  remoteDetail?: CmdMaterialSpace.MaterialDetail;
  materialKind?: string; // 材料类别
  disabled?: boolean; // 新增属性，控制表单是否可编辑
  onValuesChange?: (values: FormProps) => void; // 新增，表单值变化时回调
  propertyFormInitialValues: Partial<FormProps>; // 表单初始值
  formSettings: FormInstance<FormProps>;
}

const MaterialPropertyForm: React.FC<
  MaterialPropertyFormProps<CmdMaterialSpace.MaterialPropertyFormValues>
> = ({
  remoteDetail,
  materialKind,
  disabled = false, // 默认可编辑
  onValuesChange,
  propertyFormInitialValues,
  formSettings,
}) => {
  useEffect(() => {
    if (remoteDetail) {
      formSettings.setFieldsValue({
        ...remoteDetail?.nextMaterialAttrResultVO,
        name: remoteDetail?.name,
        materialKind: materialKind,
      });
    }
  }, [remoteDetail]);
  return (
    <Form
      colon={false}
      labelAlign='left'
      form={formSettings}
      size='small'
      labelCol={{ span: 6 }}
      initialValues={{ ...propertyFormInitialValues }}
      wrapperCol={{ span: 12 }}
      className='w-full p-2'
      onValuesChange={(_, values) => onValuesChange?.(values)}
    >
      {/* 基本属性 */}
      <div className='font-semibold text-base mb-2 text-[#464681]'>
        基本属性
      </div>
      <div className='pl-2'>
        <Form.Item
          name='name'
          label='材料名称'
        >
          <Input disabled={disabled} />
        </Form.Item>

        <Form.Item
          name='materialKind'
          label='材料类别'
        >
          <Input disabled />
        </Form.Item>

        <Form.Item
          name='modeType'
          label='模型类型'
        >
          <Select
            options={[{ value: '线性弹性各向同性', label: '线性弹性各向同性' }]}
            disabled={disabled}
          />
        </Form.Item>
      </div>

      {/* 物理属性 */}
      <div className='font-semibold text-base mt-6 mb-2 text-[#464681]'>
        物理属性
      </div>
      <div className='pl-2'>
        <Form.Item
          name={'youngsModulus'}
          label='杨氏模量'
        >
          <Input disabled={disabled} />
        </Form.Item>

        <Form.Item
          name={'poissonsRatios'}
          label='泊松比'
        >
          <Input disabled={disabled} />
        </Form.Item>

        <Form.Item
          name={'massDensity'}
          label='质量密度'
          rules={[{ required: true, message: '输入质量密度' }]}
        >
          <Input disabled={disabled} />
        </Form.Item>

        <Form.Item
          name={'thermalExpansionCoefficient'}
          label='热膨胀系数'
        >
          <Input disabled={disabled} />
        </Form.Item>

        <Form.Item
          name='yieldStrength'
          label='屈服强度'
        >
          <Input disabled={disabled} />
        </Form.Item>
      </div>
    </Form>
  );
};

export default MaterialPropertyForm;
